package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.SetMealService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("mobile/setmeal")
@Slf4j

public class SetmealController {
    @DubboReference
    private SetMealService setMealService;
    @DubboReference
    private CheckItemService checkItemService;

    @GetMapping("getSetmeal")
    public Result findAll() {
        List setmealList = setMealService.findAll();
//        获取单项检查项
        List<CheckItem> all = checkItemService.findAll();
        for (CheckItem item : all) {
            setmealList.add(item);
        }
        return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS, setmealList);
    }

    @GetMapping("findById")
    public Result findById(Integer id) {
        Setmeal setmeal = setMealService.findById(id);
        return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS, setmeal);
    }

}
